package com.aurora.oa.work.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aurora.oa.R;
import com.aurora.oa.work.bean.PersonComponentBean;

import java.util.List;

/**
 * Created by Administrator on 2017/3/15 0015.
 */
public class PersonComponentAdapter extends RecyclerView.Adapter<PersonComponentAdapter.MViewHolder> {

    private Context context;
    private LayoutInflater mInflater;
    private List<PersonComponentBean> ItemDatas;
    private OnItemClickListener onItemClickListener;
    @Override
    public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MViewHolder viewHolder = new MViewHolder(mInflater.inflate(
                R.layout.view_top_image_item, parent, false));
        return viewHolder;
    }

    public void setOnClickListener(OnItemClickListener onClickListener){
        onItemClickListener = onClickListener;
    }

    @Override
    public void onBindViewHolder(MViewHolder holder,  int position) {
        holder.tv_subtitle.setVisibility(View.GONE);
        holder.tv_title.setText(ItemDatas.get(position).getTitle());
        holder.iv_item.setImageResource(ItemDatas.get(position).getImageResID());
        holder.itemView.setTag(holder.getLayoutPosition());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemClickListener.onItemClick(Integer.parseInt(view.getTag()+""));
            }
        });

    }

    public PersonComponentAdapter(Context context,List<PersonComponentBean> personComponentBeanList) {
        this.ItemDatas = personComponentBeanList;
        mInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public int getItemCount() {
        return ItemDatas.size();
    }

    class MViewHolder extends RecyclerView.ViewHolder{


        private TextView tv_title;
        private TextView tv_subtitle;
        private ImageView iv_item;
        public MViewHolder(View itemView) {
            super(itemView);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
            tv_subtitle = (TextView) itemView.findViewById(R.id.tv_subtitle);
            iv_item = (ImageView) itemView.findViewById(R.id.iv_item);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(int position);
    }
}
